home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 19 / CD_ASCQ_19_010295.iso / dos / prg / pas / swag / oop.swg / 0048_Tinput for Passwords.pas < prev    next >
Pascal/Delphi Source File  |  1994-11-30  |  1KB  |  43 lines

  1. {
  2. > A tiny question for the TV programmers (for me a big problem). I want to
  3. > add a password to my TV program, so when I select a certain menu item, a
  4. > dialog box must appear, where I have to give my password. Is there an easy
  5. > solution to change the TInputline in this way that, if I enter a string,
  6. > only '*' are displayed at the inputline.
  7. }
  8. type
  9.   PPasswordLine = ^TPasswordLine;
  10.   TPasswordLine = object(TInputLine)
  11.     procedure Draw; virtual;
  12.   end;
  13.  
  14. implementation
  15.  
  16. procedure TPasswordLine.Draw;
  17. var
  18.   Color: Byte;
  19.   L, R: Integer;
  20.   B: TDrawBuffer;
  21.   S: String;
  22. begin
  23.   if State and sfFocused = 0 then
  24.     Color := GetColor(1) else
  25.     Color := GetColor(2);
  26.   MoveChar(B, ' ', Color, Size.X);
  27.   S:=Copy(Data^, FirstPos + 1, Size.X - 2);
  28.   FillChar(S[1],length(S),'*');
  29.   MoveStr(B[1], S, Color);
  30.   if CanScroll(1) then MoveChar(B[Size.X - 1], #16, GetColor(4), 1);
  31.   if State and sfFocused <> 0 then
  32.   begin
  33.     if CanScroll(-1) then MoveChar(B[0], #17, GetColor(4), 1);
  34.     L := SelStart - FirstPos;
  35.     R := SelEnd - FirstPos;
  36.     if L < 0 then L := 0;
  37.     if R > Size.X - 2 then R := Size.X - 2;
  38.     if L < R then MoveChar(B[L + 1], #0, GetColor(3), R - L);
  39.   end;
  40.   WriteLine(0, 0, Size.X, Size.Y, B);
  41.   SetCursor(CurPos - FirstPos + 1, 0);
  42. end;
  43.